<?php
namespace app\home\controller;

use think\Controller;
use think\Db;
class User extends Controller
{
    public function register(){
        if(request()->isPost()){
            $data=input('post.');
            Db::name('user')->insert($data);
            $this->success('注册成功');
        }
        return view();
    }
    public function login(){
        if(request()->isPost()){
            $data= input('post.');
            $res=db('user')->where(['name'=>$data['name'],'pwd'=>$data['pwd']])->select();
            // print_r($res);
            // exit;
            if(!empty($res)){
                echo "登录成功";
            }else{
                $this->error('账号或密码错误');
            }
        }
        return view();
    }
    public function lst(){
        $data=db('user')->select();
        dump($data);
    }


    public function isName(){
        if(request()->isAjax()){
            $data= input('post.');
            $res=db('user')->where(['name'=>$data['name']])->select();
            if(!empty($res)){
                echo 1;
            }else{
                echo 0;
            }
        }
    }
}